//index.js
//获取应用实例
const app = getApp();

Page({
  data: {
    caregory:[],
    url:'https://hl.gzziyu.com/mobile/',
    guanggao: 'https://hl.gzziyu.com/mobile/data/afficheimg/',
    guanggaoimg:[]
  },
  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123'
    }
  },
  go_xiangche:function(e){
    wx.navigateTo({
      url: '../xiangche/xiangche',
    })
  },
  go_shop:function(){
    wx.switchTab({
      url:'../shop/shop'
    })
  },

  go_url:function(e){
    if (e.currentTarget.dataset.url == "../shop/shop"){
      wx.switchTab({
        url: e.currentTarget.dataset.url
      })
    }else{
      wx.navigateTo({
        url: e.currentTarget.dataset.url,
      })
    }
    // wx.reLaunch({
    //   url: e.currentTarget.dataset.url,
    // })
  },
  // 去竞猜
  go_jingcai:function(){
    wx.switchTab({
      url: '../cai/cai',
    })
  },
  // 去商品详情
  go_shop_detail:function(e){
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../product_detail/product_detail?id='+e.currentTarget.dataset.id,
    })
  },
  go_meinv_detail:function(e){
    wx.navigateTo({
      url: '../meinv_detail/meinv_detail?id='+e.currentTarget.dataset.id,
    })
  },
  onLoad: function () {
    var that = this;
    // 推荐
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.url+'ziyu.php?Action=product',
      success:function(res){
        console.log('商城')
        console.log(res)
        that.setData({
          shop_list:res.data
        })
      }
    })
    // 顶部导航
    wx.request({
      url: 'https://hl.gzziyu.com//mobile/ziyu.php?Action=ctype',
      success:function(res){
        console.log(res)
        that.setData({
          caregory:res.data
        })
      }
    })
    // 有奖竞猜
    wx.request({
      url: 'https://hl.gzziyu.com//mobile/ziyu.php?Action=danzhang&shuzi=3',
      success:function(res){
        console.log(res)
        that.setData({
          guanggaoimg: res.data
        })
      }
    })
    // 香车美女数据
    wx.request({
      url: app.globalData.url + 'ziyu.php?Action=article_cat&id=4',
      success: function (res) {
        console.log(res)
        var arr = []
        for (var i in res.data) {
          arr.push(res.data[i]); //属性
        }
        that.setData({
          meinv: arr.slice(0,2)
        })
        wx.hideLoading()
      }
    })

   
   

  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onShareAppMessage: function () {
    return {
      title: '鸿浪爱车连锁，专业服务20年！',
      path: 'pages/index/index',
      imageUrl:"https://hl.gzziyu.com/mobile/data/cat_ico/1541441252786367470.jpg"

    }
  }
  
})
